#include <iostream>
#include <string>
#include <regex>

using namespace std;

int main()
{
    string str = "GET /biejiuyeke/login?user=xiaoming&passwd=123123 HTTP/1.1\r\n";
    // //string str = "GET /biejiuyeke/login HTTP/1.1\r\n";
    // smatch matches;
    // regex e("(GET|HEAD|POST|PUT|DELETE) ([^?]*)(?:\\?(.*))? (HTTP/1\\.[01])(?:\r\n|\n)?");//匹配的更准确，更贴近。字符串不会乱
    // //regex e("(GET|HEAD|POST|PUT|DELETE) (\\/[^?]*)\\?(user=.*&passwd=.*) (HTTP/1\\.[01])");
    // string str = "GET /biejiuyeke/login? HTTP/1.1\r\n";
    smatch matches;
    regex e("(GET|HEAD|POST|PUT|DELETE) ([^?]*)\\?(.*)? (HTTP/1\\.[01])(?:\r\n|\n)?", std::regex::icase);//匹配的更准确，更贴近。字符串不会乱
    //regex e("(GET|HEAD|POST|PUT|DELETE) (\\/[^?]*)\\?(user=.*&passwd=.*) (HTTP/1\\.[01])");
    bool ret = regex_match(str, matches, e);
    if (ret == false)
        return -1;
    std::string method = matches[1];
    std::transform(method.begin(), method.end(), method.begin(), ::toupper);    //对该范围里的每个元素都进行函数操作，第三个参数是将结果放到哪个位置
    int i = 0;
    for (auto& s : matches)
    {
        printf("%d: ", i);
        i++;
        cout << s;
        printf(" size:%d\n", s.length());
    }
    
    return 0;
}